<?php

!defined('IN_HDWIKI') && exit('Access Denied');

class control extends base{

	function control(& $get,& $post){
		$this->base( & $get,& $post);
		$this->load('user');
		$this->view->setlang($this->setting['lang_name'],'back');
	}

	function dodefault(){
		$this->dologin();
	}

	function doupdate(){
		include_once HDWIKI_ROOT.'/lib/xmlparser.class.php';
		$sendversion = base64_encode( serialize( array('v'=>HDWIKI_VERSION,'r'=>HDWIKI_RELEASE,'c'=>WIKI_CHARSET,'u'=>$this->setting['site_url']) ) );
		$xmlfile="http://kaiyuan.hudong.com/update.php?v={$sendversion}";
		$xmlparser = new XMLParser();
		$xmlnav=$xmlparser->parse($xmlfile);
		$isupdate = $xmlnav[0]['child'][0]['content'];
		$version = $xmlnav[0]['child'][1]['content'];
		$release = $xmlnav[0]['child'][2]['content'];
		$url = $xmlnav[0]['child'][3]['content'];
		$description = $xmlnav[0]['child'][4]['content'];
		$json = '{"isupdate":"'.$isupdate.'","version":"'.$version.'","release":"'.$release.'","url":"'.$url.'","description":"'.$description.'"}';
		echo $json;
	}

 	function dologin(){
		$admin_mainframe = $this->hgetcookie('querystring') ? $this->hgetcookie('querystring'):'admin_main-mainframe';
		$this->view->assign('admin_mainframe', $admin_mainframe);
 		if(2==$this->user['islogin']){
 			$this->view->display("admin_main");
 			exit;
 		}
 		if($this->user['islogin']){
			if(!isset($this->post['password'])){
				$this->view->display("admin_login");
			}else{
				if( $this->user['password'] != md5($this->post['password']) ){
					$this->view->assign('loginmsg',$this->view->lang['commonPasswdIsWrong']);
					$this->view->display("admin_login");
					exit;
				}else{
					$session['islogin']=2;
					$_ENV['user']->update_session($session,$this->user['sid']);
					$this->view->display("admin_main");
					exit;
				}
			}
		}else{
			$this->header('user-login');
		}
	}

 	function dologout(){
 		$session['islogin']=1;
		$_ENV['user']->update_session($session,$this->user['sid']);
		$this->header();
	}

	function domainframe(){
		$sys['server'] = PHP_OS.' / PHP v'.PHP_VERSION;
		$mysql=$this->db->fetch_first('SELECT VERSION() AS version');
		$sys['mysql']=$mysql['version'];
		$this->view->assign('sys', $sys);
		$this->view->display("admin_mainframe");
	}
}
?>